package xiegd.study.regular;

import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.junit.Test;
import org.junit.platform.commons.util.StringUtils;
//import org.junit.platform.commons.util.StringUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
 * @Description:
 * @Author: xieguangda
 * @Date: 2021年06月21日 15:39
 *
 *
 */
public class RegularStudy {

    /**
     * 所属联创
     *
     * 正则
     *
     * 只能输入这四个字
     */

    @Test
    public void showDirect(){
      //  String s = "我是一个兵222";

        String regex = "^[\\u4e00-\\u9fa5]{0,}$";

        List<String> list = Arrays.asList(
                "所属联创"
        );

        Pattern pattern1 = Pattern.compile("([^所]+)");
        for (String s : list) {
            Matcher m = pattern1.matcher(s);
            if (m.find()) {
                System.out.println(m.group());
            } else {
                System.out.println("没有提前天数");
            }
        }

       // boolean flag = s.matches(regex);//判断功能
       // System.out.println("flag:"+flag);
    }


    private static boolean checkQQ(String qq) {
        return qq.matches("[1-9]{1}\\d{4,14}");
    }

    @Test
    public void testRegularExpression() {
        List<String> list = Arrays.asList(
                "提前0-购票折扣率",
                "0-2天（含第2天）购票折扣率",
                "2天外（不含第2天）购票折扣率",
                "3天外购票折扣率",
                "提前0-2天购票折扣率",
                "提前2-3天购票折扣率",
                "购票折扣率",
                "折扣率"
        );

        Pattern pattern = Pattern.compile("([^购票折扣率]+)");
        for (String s : list) {
            Matcher m = pattern.matcher(s);
            if (m.find()) {
                System.out.println(m.group());
            } else {
                System.out.println("没有提前天数");
            }
        }
    }


    @Test
    public void test003(){
        String string1 = "我爱编w!@#程www#" +
                "她不5454 dadad &*$()###(爱编dadada程w!";

     String regEx="[`~!@#$%^&*()+=|{}:;\\[\\].<>/?~！@#￥%……&*（）——+|{}【】‘；：”“’。，、？a-zA-Z0-9 ]";
     Pattern c = Pattern.compile(regEx);
     Matcher mc=c.matcher(string1);
     String result =mc.replaceAll("").trim();
     System.out.println(result);

     Pattern p = Pattern.compile("[编][程]");
     Matcher m = p.matcher(result);
     while(m.find()){
         System.out.println(m.group());
     }

    }


    @Test
    public void test333(){

        String regex = "^[a-zA-Z0-9]+$";

        Pattern pattern = Pattern.compile(regex);

        Matcher matcher = pattern.matcher("123-AbC");

        System.out.println("我看看：：：" + matcher.matches());
    }


    @Test
    public void mytet33(){
        String str = "B123A";
        String m = "^[a-zA-Z0-9]+$";
        if (StringUtils.isBlank(str)) {
            return;
        }
        //return str.matches(m);
        System.out.println("我看看：：：" + str.matches(m) + ","+  str.length());
    }

    @Test
    public void test(){
        Long b123A = extractNum("B123A");
        System.out.println("我看看2：" + b123A);
    }

    private static final Pattern NUM = Pattern.compile("[^0-9]");

    /**
     * 提取数字
     */
    private static Long extractNum(String num) {
        Long l = null;
        if (num.length() < 10) {
            Matcher m = NUM.matcher(num);
            String result = m.replaceAll("").trim();
            l = Long.valueOf(result);
        }
        return l;
    }

    @Test
    public void test333333(){

//        StringUtils.leftPad("123", 6, "0");
//        StringUtils.isNotBlank("");

        List<RooM> mytestList = new ArrayList<>();
//        mytestList.add(RooM.builder().roomNum("A103").id(1).build());
//        mytestList.add(RooM.builder().roomNum("1").id(1).build());
//        mytestList.add(RooM.builder().roomNum("103A").id(1).build());


        mytestList.add(RooM.builder().roomNum("903A").id(2).build());
        mytestList.add(RooM.builder().roomNum("903").id(3).build());
//        mytestList.add(RooM.builder().roomNum("905").id(4).build());
//        mytestList.add(RooM.builder().roomNum("913C").id(5).build());
//        mytestList.add(RooM.builder().roomNum("913A").id(6).build());
//        mytestList.add(RooM.builder().roomNum("913a").id(6).build());
//        mytestList.add(RooM.builder().roomNum("913B").id(7).build());
//        mytestList.add(RooM.builder().roomNum("1002").id(8).build());
//        mytestList.add(RooM.builder().roomNum("1003").id(9).build());
//        mytestList.add(RooM.builder().roomNum("AA").id(7).build());
        mytestList.sort((a,b)->a.getRoomNum().compareTo(b.getRoomNum()));
//
//        System.out.println("我是第一个排序：：" + mytestList);

        Comparator<RooM> rooMComparator = (a, b)->{
            int sort = 0;
            String roomNumStr = a.getRoomNum();
            String roomNumStr2 = b.getRoomNum();

            String roomNum = roomNumStr.replaceAll("\\pL", "");
            String roomNum1 = roomNumStr2.replaceAll("\\pL", "");
            if(StringUtils.isNotBlank(roomNum) && StringUtils.isNotBlank(roomNum1)){
                Integer roomNumInteger = new Integer(roomNum);
                Integer roomNum1nteger1 = new Integer(roomNum1);
                //先按照纯数字排序
                if(roomNumInteger > roomNum1nteger1){
                    return 1;
                }else if(roomNumInteger < roomNum1nteger1){
                    return -1;
                }
                //如果数字一样
                if(roomNumInteger.equals(roomNum1nteger1)){
                    //，则按照字母长的再后面
                    if(roomNumStr.length() > roomNumStr2.length()){
                        return 1;
                    }else if(roomNumStr.length() < roomNumStr2.length()){
                       return -1;
                    } else {

//                    } else {    //字母长度一样，则按照字母排序
                        if (roomNumStr.compareTo(roomNumStr2) < 0) {
                            return -1;
                        } else {
                            return 1;
                        }
                    }
                }
            }
            return sort;
        };

        List<RooM> collect = mytestList.stream().sorted(rooMComparator).collect(Collectors.toList());
        List<String> collect1 = collect.stream().map(e -> e.getRoomNum()).collect(Collectors.toList());
        System.out.println("看啊看哈：：" + JSONObject.toJSONString(collect1));
    }



    @Test
    public void mytest344(){
        String s1 = "101A";
        String s2 = "101";

        System.out.println("比较看啊可能：" + s1.compareTo(s2));// 101A 101B -1  -32               101 101A 1  roomNumStr.compareTo(roomNumStr2) < 0
    }

    @Test
    public void uploadTest(){
        String a = "103A";
        String b = "103aaa";

        String s = b.toUpperCase();
        System.out.println("b:" + b + ",s:" + s);
    }
}


@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
class RooM{
    private String roomNum;

    private Integer id;
}


